﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Com;
using Core;
using Models;

namespace Controllers
{
    public class AdmintypeController : AdminBaseController
    {
        admintypeCore core = new admintypeCore();
        public ActionResult Get(int id)
        {
            if (!HasQx("usertype"))
            {
                return Error("没有权限！");
            }
            return Success(core.GetOne(id));
        }

        public ActionResult GetAll()
        {
            if (!HasQx("usertype"))
            {
                return Error("没有权限！");
            }
            return Success(core.GetList("", "ID desc", null));
        }
        public ActionResult GetList(pageinfo pageinfo)
        {
            if (!HasQx("usertype"))
            {
                return Error("没有权限！");
            }
            List<object> argsList = new List<object>();
            string where = string.Empty;
            var list = core.GetPage(pageinfo.page,pageinfo.pagesize, where, pageinfo.order+" "+pageinfo.esc, argsList.ToArray());
            return Success(list);
        }
        
        [HttpPost]
        public ActionResult Del(int id)
        {
            if (!HasQx("usertype"))
            {
                return Error("没有权限！");
            }
            if (id > 0)
            {
                if (core.Del(id))
                {
                    Log(curmanage.username + "删除用户角色ID=" + id);
                    return Success("删除成功！");
                }

            }
            return Error("删除失败！");
        }
        [HttpPost]
        public ActionResult DelAll(List<admintypeEntity> modelList)
        {
            if (!HasQx("usertype"))
            {
                return Error("没有权限！");
            }
            string ids = string.Empty;
            foreach (var admintypeEntity in modelList)
            {
                core.Del(admintypeEntity);
                ids += admintypeEntity.ID + ",";
            }
            ids = ids.TrimEnd(',');
            Log(curmanage.username +  "删除用户角色ID in (" + ids + ")");
            return Success("删除成功！");
        }
        [HttpPost]
        public ActionResult Save(admintypeEntity info)
        {
            if (!HasQx("usertype"))
            {
                return Error("没有权限！");
            }
            if (info.typename == null)
            {
                return Error();
            }
            var model = core.Save(info);
            Log(curmanage.username + "保存用户角色" + model.ToJson());
            return Success(model);
        }
    }
}
